package springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springcloud.config.Result;
import springcloud.entity.MovieInfo;
import springcloud.service.IMoiveInfoService;

/**
 * 电影信息 前端控制器
 */
@Api(value = "电影表管理", tags = "电影表管理模块")
@RestController
@RequestMapping("/movie")
public class MovieInfoController {

  @Autowired
  private IMoiveInfoService iMoiveInfoService;

  @PostMapping("/today/list")
  @ApiOperation("今日电影列表查询")
  @HystrixCommand
  public Result<?> getMoiveListToday() {
    try {
      return iMoiveInfoService.getMoiveListToday();
    } catch (Exception e) {
      e.printStackTrace();
      return Result.fail(e.getMessage());
    }
  }

  @PostMapping("/today/getById")
  @ApiOperation("通过ID查询电影详情")
  @ApiImplicitParam(value = "电影ID", name = "id", dataType = "Integer")
  public MovieInfo getMoiveDetail(Integer id) {
    return iMoiveInfoService.getMoiveDetail(id);
  }

  @PostMapping("/today/updateById")
  @ApiOperation("更新电影票数量")
  @ApiImplicitParams({
          @ApiImplicitParam(value = "电影ID", name = "id", dataType = "Integer"),
          @ApiImplicitParam(value = "购买张数", name = "number", dataType = "Integer")
  })
  @HystrixCommand
  public Result<String> updateMovieNum(Integer id, Integer number) {
    return iMoiveInfoService.updateMovieNum(id,number);
  }

  //下面全局fallback方法
  public Result<?> global_FallbackMethod(){
    return Result.fail("请检查你的传入参数，网络情况是否良好");
  }
}
